<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="product" tagdir="/WEB-INF/tags/product"%>

<c:set var="title"><fmt:message key="productForm.selectOptionValue.dialog.title"/></c:set>
<c:set var="buttonTxt"><fmt:message key="productForm.selectOptionValue.dialog.buttonTxt"/></c:set>

<%-- 
<%@include file="productFormOptionValueMultiChoices.jspf" %>
<a onclick="genSkus('skuTable')">gen</a>
--%>
<probiz:ui_dialog id="optionValueChoies" title="${title}" width="600" height="400" buttons="${buttonTxt}:genSkus">
	<%@include file="productFormOptionValueMultiChoices.jspf" %>
</probiz:ui_dialog>


<div  class="p_sku">
	<table width="100%" border="0" cellspacing="0" cellpadding="0" class="com_modi_table">
		<tr>
			<th colspan="2" class="title"><h4><fmt:message key="productDetail.group.sales"/><h4></th>
		</tr>
	</table>	
	
	<verFunc:verFuncValidate funcKey="multiSku">
		<div id="changeToMultiSkusBar" class="title" <c:if test="${product.isSetMultiSkus == 1}">style="display:none;"</c:if>>
			<a href="javascript:void(0)" onclick="openGenSkusDialog();" id="changeToMultiSkusButton" class="sku_open" quickTip="<fmt:message key="productForm.changeToMultiSkus.tip" />"></a>
		</div>	
	</verFunc:verFuncValidate>
	
	<div id="addSkuBar" class="title"  <c:if test="${empty product.isSetMultiSkus or product.isSetMultiSkus == 0}">style="display:none;"</c:if> >
		<a href="javascript:void(0)" onclick="newSku('skuTable')" id="addSkuButton" class="sku_add" quickTip="<fmt:message key="productForm.addSku.tip" />"></a>
		&nbsp;&nbsp;&nbsp;<fmt:message key="productForm.skuOptionSelect"/>:
		<span id="optionSelectSpan">
			<c:forEach items="${skuOptionList}" var="skuOption">
				<c:set var="optionIdD" value="${skuOption.skuOptionId},"/>
				<input type="checkbox" id="skuOptionCheckbox_${skuOption.skuOptionId}" name="skuOptionCheckbox" <c:if test='${fn:contains(optionIds,optionIdD)}'>checked</c:if>  onclick="toggleSkuOption(this,true);"/>
				${skuOption.skuOptionName}
				<input type="hidden" name="selectedOptions" value="${skuOption.skuOptionId}"  <c:if test='${!fn:contains(optionIds,optionIdD)}'>disabled</c:if>/>
			</c:forEach>
			<c:if test="${empty skuOptionList}">
				<fmt:message key="productForm.noOpenSkuOption">
					<fmt:param value="reDefineProductType()"/>
				</fmt:message>
			</c:if>
		</span>
	</div>	
	
	
	<input type="hidden" id="isSetMultiSkus" name="isSetMultiSkus" value="${(product.productId == null)?0:product.isSetMultiSkus}"/>
	<div id="skuTable" name="skuTable"></div>
	
</div>


<script type="text/javascript">
$j(document).ready(function () {
	<%--start:初始化规格数组和规格值数组--%>
	<c:forEach items="${skuOptionList}" var="skuOption">
		skuOptionArray.push({"id":"${skuOption.skuOptionId}","name":"${skuOption.skuOptionName}"});
		var skuOptionValueSingleArray = new Array();
		<c:forEach items="${skuOption.skuOptionValues}" var="skuOptionValue">
			skuOptionValueSingleArray.push({"optionId":"${skuOptionValue.skuOption.skuOptionId}" ,"id":"${skuOptionValue.skuOptionValueId}","name":"${skuOptionValue.skuOptionValueName}","value":"${skuOptionValue.skuOptionValue}","type":"${skuOptionValue.skuOptionValueType}"})
		</c:forEach>
		skuOptionValueArray.push(skuOptionValueSingleArray);
	</c:forEach>
	
	optionIds = "${optionIds}";
	<%--end:初始化规格数组和规格值数组--%>
	
	<%--start:初始化sku--%>
	<c:choose>
		<c:when test="${fn:length(product.productSkus) == 0}">
			var wholesalePriceTableId = addSku("skuTable",null);
			changeToSingleSku("skuTable");
			closeSkuOptions();
		</c:when>
		<c:otherwise>
			<c:forEach items="${product.productSkus}" var="sku">
				var wholesalePriceTableId = addSku("skuTable",{id:${sku.productSkuId},code:"${sku.productSkuCode}",imageUrl:"${sku.imageUrl}",listPrice:"${sku.listPrice}",price:"${sku.price}",salePrice:"${sku.salePrice}",weight:"${sku.weight}",inventory:"${sku.inventory.quantityOnHand}",optionValueInfo:"${sku.skuOptionValueInfo}",allocatedQuantity:"${sku.inventory.allocatedQuantity}"});
				<c:forEach items="${sku.wholesalePrices}" var="wp" varStatus="wpStatus">
					addWholesalePrice(wholesalePriceTableId,{wpId:${wp.wholesalePriceId},wpSkuId:${wp.productSkuId},wpMinQuantity:"${wp.minQuantity}",wpMaxQuantity:"${wp.maxQuantity}",wpPrice:"${wp.price}",wpDeliveryDay:""},${wpStatus.index == 0});
				</c:forEach>
			</c:forEach>
			<c:choose>
				<c:when test="${(empty product.isSetMultiSkus) or (product.isSetMultiSkus == 0)}">
					changeToSingleSku("skuTable");
				</c:when>
				<c:otherwise>
					changeToMultiSkus("skuTable");	
				</c:otherwise>
			</c:choose>
			
		</c:otherwise>
	</c:choose>	
	<%--end:初始化sku--%>
	
	//start:quickTip 生成 原因：在tag中$j无法扑捉到对象;另外直接用id指定是为了提高在ie下的查找速度
	$j('#changeToMultiSkusButton,#addSkuButton').each(function(){
      	$j(this).after('<img id="'+this.id+'_tip" width="14" height="14" src="'+__ctxPath+'/images/validate/info.gif"/>');
		$j('#'+this.id+'_tip').PQuickTip({
	         source:'text',
	         title:'Help',
	         type:'help',
	         text:$j(this).attr("quickTip")
      	});
	
	});
	//end:quickTip 生成
});	
</script>	
